﻿#pragma once

#include "qserialport.h"
#include "qserialportinfo.h"
#include "qbytearray.h"

#include "LogSaver.h"

class SerialPortManager :public QSerialPort
{
	Q_OBJECT

private:
	bool listenerState;//监听状态
private://dependency
	LogSaver* logSaver= LogSaver::getLogSaver();//通过静态函数获得全局默认的日志记录器
public:
	explicit SerialPortManager(QObject* parent = Q_NULLPTR);
	virtual ~SerialPortManager();

signals:
	void dataReceived(QByteArray data);//收到数据会发送该信号
public slots:
	bool sendData(QByteArray data);
	bool startListener();
	void stopListener();

public:
	bool isListening();
private slots:
	void readData();
	//初始化函数
private:
	void initSerialPort();
};
